package com.hyt.it.ogt.kq.service.bm.feign.file;

import com.hyt.common.utils.exception.BusinessException;
import com.hyt.it.ogt.kq.service.bm.feign.tps.TpsClientHystrix;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;


/**
 * 文件服务Feign客户端
 */
@FeignClient(value = "it-ogt-webcommon",contextId = "it-ogt-webcommon-fds",fallbackFactory = TpsClientHystrix.class)
public interface FileClient {  
	
	/**
	 * @Description: 上传文件
	 * @param file 文件对象
	 * @return 文件路径
	 */
	@RequestMapping(value = "/file/upload/multipartfile",
			method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	String uploadFile(@RequestPart(value = "file") MultipartFile file);
	
	/**
	 * @Description: 上传文件
	 * @param bytes 文件数据
	 * @param format 文件格式（后缀）
	 * @return String 文件路径
	 */
	@RequestMapping(value = "/file/upload/bytes", method = RequestMethod.POST)
	String uploadFile(@RequestBody byte[] bytes, @RequestParam String format);
	
	/**
	 * @Description: 把字符串作为指定格式的文件上传
	 * @param content 
	 * @param fileExtension 
	 * @return String 
	 */
	@RequestMapping(value = "/file/upload/string", method = RequestMethod.POST)
	String uploadFile(@RequestParam String content, @RequestParam String fileExtension);
	
	/**
	 * 
	 * @param url 上传文件地址
	 * @param fileSize 文件大小
	 * @param fileExtension 文件扩展名
	 * @return 返回文件地址
	 */
	@RequestMapping(value = "/file/upload/url", method = RequestMethod.POST)
	String uploadFileByUrl(@RequestParam String url,
			@RequestParam long fileSize, @RequestParam String fileExtension);
	
	/**
	 * @Description: 上传图片并生成缩略图
	 * @param file 文件对象
	 * @return 文件路径
	 */
	@RequestMapping(value = "/file/upload/image/crtthumbimage",
			method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
	String uploadImageAndCrtThumbImage(@RequestPart(value = "file") MultipartFile file);
	
	/**
	 * @Description: 根据图片路径获取缩略图路径（使用uploadImageAndCrtThumbImage方法上传图片）
	 * @param filePath 图片路径
	 * @return String 缩略图路径
	 */
	@RequestMapping(value = "/file/get/thumbimagepath", method = RequestMethod.GET)
	String getThumbImagePath(@RequestParam String filePath);
	


	/**
	 * @Description: 根据文件地址删除文件
	 * @param filePath 文件访问地址
	 */
	@RequestMapping(value = "/file/delete", method = RequestMethod.DELETE)
	void deleteFile(@RequestParam String filePath);

	@RequestMapping(value = "/file/down", method = RequestMethod.GET)
	byte[] downFile(@RequestParam String filePath) throws BusinessException ;

	@RequestMapping(value = "/file/downFileByStream", method = RequestMethod.GET)
	InputStream downFileByStream(@RequestParam String filePath);


}
